package com.getpebble.android.main.sections.support.activity;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import com.getpebble.android.PebbleApplication;
import com.getpebble.android.R;
import com.getpebble.android.common.core.trace.Trace;
import com.getpebble.android.main.activity.TapToConnectActivity;

public abstract class SingleFragmentActivity extends TapToConnectActivity {
    public static final String TAG = SingleFragmentActivity.class.getSimpleName();

    public abstract int getLayoutId();

    public abstract int getTitleStringId();

    public void onCreate(Bundle savedInstanceState) {
        Trace.debug(TAG, "onCreate");
        requestWindowFeature(8);
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            Trace.debug(TAG, "Setting up action bar");
            actionBar.setTitle(getString(getTitleStringId()));
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setIcon(getActionBarIconId());
            actionBar.show();
            return;
        }
        Trace.debug(TAG, "No action bar");
    }

    public int getActionBarIconId() {
        return R.drawable.ic_drawer_mypebble;
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() != 16908332) {
            return super.onOptionsItemSelected(item);
        }
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }

    public void onStart() {
        super.onStart();
        PebbleApplication.onActivityOnStart();
    }

    public void onStop() {
        super.onStop();
        PebbleApplication.onActivityOnStop();
    }
}
